//
//  Regex.m
//  TPS
//
//  Created by 左学良 on 16/5/18.
//  Copyright © 2016年 TPS. All rights reserved.
//

#import "Regex.h"

@implementation Regex


//  验证手机号码
+ (BOOL)isValidatePhoneNumber:(NSString *)mobileNumber{
    // 判断是不是手机号码
    NSString * MOBILE = @"1[0-9]{10}";
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    return [regextestmobile evaluateWithObject:mobileNumber];
}

//  验证密码
+ (BOOL)isValidatePassword:(NSString *)passwordStr{
    
//    NSString *password = @"^(?![\\d]+$)(?![a-zA-Z]+$)(?![!#$%^&*]+$)[\\da-zA-Z!#$%^&*]{6,16}$";
    NSString *password = @"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$";
    NSPredicate *regextestPassword = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", password];
    return ![regextestPassword evaluateWithObject:passwordStr];
}

+ (BOOL)isValidateEmail:(NSString *)emailStr
{
    NSString *email = @"[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[\\w](?:[\\w-]*[\\w])?";
    NSPredicate *regextestEmail = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", email];
    return [regextestEmail evaluateWithObject:emailStr];
}

/**< 验证是否是浮点数 */
+ (BOOL)isValidateFloatPointNumber:(NSString *)number
{
    NSString *email = @"^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$";
    NSPredicate *regextest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", email];
    return [regextest evaluateWithObject:number];
}
/**< 验证是否是两位小数 */
+ (BOOL)regexTwoDecimalPlace:(NSString *)number
{
    NSString* regex = @"(^[0-9]$)|(^[1-9]\\d*$)|(^[0-9][\\.]{1}[0-9]{1,2}$)|(^[1-9]\\d*[\\.]{1}[0-9]{1,2}$)|(^[0-9][\\.]$)|(^[1-9]\\d*[\\.]$)";
    NSPredicate* regexTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    return [regexTest evaluateWithObject:number];
}

/**< 验证是否是两位小数 */
+ (BOOL)regexTwelveInterAndTwoDecimalPlace:(NSString *)number
{
    NSString* regex = @"(^[0-9]$)|(^[1-9]\\d{1,11}$)|(^[0-9][\\.]{1}[0-9]{1,2}$)|(^[1-9]\\d{1,11}[\\.]{1}[0-9]{1,2}$)|(^[0-9][\\.]$)|(^[1-9]\\d{1,11}[\\.]$)";
    NSPredicate* regexTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    return [regexTest evaluateWithObject:number];
}

+ (BOOL)regexTwoInterAndeTwoDecimalPlace:(NSString *)number
{
    NSString* regex = @"(^[0-9]$)|(^[1-9]\\d{1}$)|(^[0-9][\\.]{1}[0-9]{1,2}$)|(^[1-9]\\d{1}[\\.]{1}[0-9]{1,2}$)|(^[0-9][\\.]$)|(^[1-9]\\d{1}[\\.]$)|^100$";
    NSPredicate* regexTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    return [regexTest evaluateWithObject:number];
}

/**< 验证是否是整数 */
+ (BOOL)isValidateNumber:(NSString *)number
{
    NSString *email = @"^[0-9]*$";
    NSPredicate *regextest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", email];
    return [regextest evaluateWithObject:number];
}



@end
